﻿namespace KeRui.DAL
{
    using KeRui.DBUtility;
    using KeRui.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class AdClick
    {
        public int Add(KeRui.Model.AdClick model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@AdID", SqlDbType.Int, 4), new SqlParameter("@SellerADID", SqlDbType.Int, 4), new SqlParameter("@CreateIP", SqlDbType.VarChar, 50) };
            parameters[0].Value = model.AdID;
            parameters[1].Value = model.SellerADID;
            parameters[2].Value = model.CreateIP;
            return DbHelperSQL.RunProcedure("AdClick_ADD", parameters, out num);
        }

        public KeRui.Model.AdClick GetModel(int ID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            KeRui.Model.AdClick click = new KeRui.Model.AdClick();
            DataSet set = DbHelperSQL.RunProcedure("AdClick_GetModel", parameters, "ds");
            if (set.Tables[0].Rows.Count > 0)
            {
                if (set.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    click.ID = int.Parse(set.Tables[0].Rows[0]["ID"].ToString());
                }
                if (set.Tables[0].Rows[0]["AdID"].ToString() != "")
                {
                    click.AdID = int.Parse(set.Tables[0].Rows[0]["AdID"].ToString());
                }
                if (set.Tables[0].Rows[0]["SellerADID"].ToString() != "")
                {
                    click.SellerADID = int.Parse(set.Tables[0].Rows[0]["SellerADID"].ToString());
                }
                if (set.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    click.CreateTime = DateTime.Parse(set.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                click.CreateIP = set.Tables[0].Rows[0]["CreateIP"].ToString();
                return click;
            }
            return null;
        }
    }
}

